package zdream.pmfield.stage.director;

import java.util.HashMap;
import java.util.Map;

import zdream.pmfield.stage.Stage;

/**
 * @author Zdream
 * @date 2023-11-15
 * @since 0.0.1
 */
public class StageResult {
	public final HashMap<Integer, StageResultType> sideResultMap = new HashMap<>();

	public StageResult(Stage stage) {
		final int[] sides = stage.allFoes.stream()
				.mapToInt(foe -> foe.side)
				.distinct()
				.toArray();
		for (int side : sides) {
			sideResultMap.put(side, StageResultType.UNKNOWN);
		}
	}

	public StageResult withSideSuccess(int side) {
		if (sideResultMap.containsKey(side)) {
			sideResultMap.put(side, StageResultType.SUCCESS);
		}
		return this;
	}

	public StageResult withOtherSideFail() {
		for (Map.Entry<Integer, StageResultType> entry : sideResultMap.entrySet()) {
			if (StageResultType.UNKNOWN.equals(entry.getValue())) {
				entry.setValue(StageResultType.FAIL);
			}
		}
		return this;
	}

	public enum StageResultType {
		SUCCESS,
		FAIL,
		DRAW,
		UNKNOWN,
	}
}
